package com.retirement.csd.service.impl;

import java.util.List;

import cn.hutool.core.util.IdUtil;
import com.retirement.common.annotation.DataScope;
import com.retirement.common.utils.DateUtils;
import com.retirement.common.utils.SecurityUtils;
import com.retirement.csd.domain.EcharsServe;
import com.retirement.csd.domain.EcharsServeType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.retirement.csd.mapper.OdsOrderMapper;
import com.retirement.csd.domain.OdsOrder;
import com.retirement.csd.service.IOdsOrderService;

/**
 * 服务订单Service业务层处理
 *
 * @author ruoyi
 * @date 2024-03-13
 */
@Service
public class OdsOrderServiceImpl implements IOdsOrderService
{
    @Autowired
    private OdsOrderMapper odsOrderMapper;

    /**
     * 查询服务订单
     *
     * @param id 服务订单主键
     * @return 服务订单
     */
    @Override
    public OdsOrder selectOdsOrderById(Long id)
    {
        return odsOrderMapper.selectOdsOrderById(id);
    }

    /**
     * 查询服务订单列表
     *
     * @param odsOrder 服务订单
     * @return 服务订单
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<OdsOrder> selectOdsOrderList(OdsOrder odsOrder)
    {
        return odsOrderMapper.selectOdsOrderList(odsOrder);
    }

    @Override
    public List<EcharsServeType> selectOdsOrderTypeNums() {
        return odsOrderMapper.selectOdsOrderTypeNums();
    }


    /**
     * 新增服务订单
     *
     * @param odsOrder 服务订单
     * @return 结果
     */
    @Override
    public int insertOdsOrder(OdsOrder odsOrder)
    {
        odsOrder.setDeptId(SecurityUtils.getDeptId());
        odsOrder.setOrderNum(IdUtil.simpleUUID());
        odsOrder.setStatus("0");
        odsOrder.setOrdererId(SecurityUtils.getUserId());
        odsOrder.setCreateTime(DateUtils.getNowDate());
        return odsOrderMapper.insertOdsOrder(odsOrder);
    }

    /**
     * 修改服务订单
     *
     * @param odsOrder 服务订单
     * @return 结果
     */
    @Override
    public int updateOdsOrder(OdsOrder odsOrder)
    {
        if (odsOrder.getStatus().equals("0")){
            //接单
            odsOrder.setTakerId(SecurityUtils.getUserId());
            odsOrder.setStatus("1");
        } else if (odsOrder.getStatus().equals("1")) {
            //结束订单
            odsOrder.setStatus("2");
        }
        odsOrder.setUpdateTime(DateUtils.getNowDate());
        return odsOrderMapper.updateOdsOrder(odsOrder);
    }

    /**
     * 批量删除服务订单
     *
     * @param ids 需要删除的服务订单主键
     * @return 结果
     */
    @Override
    public int deleteOdsOrderByIds(Long[] ids)
    {
        return odsOrderMapper.deleteOdsOrderByIds(ids);
    }

    /**
     * 删除服务订单信息
     *
     * @param id 服务订单主键
     * @return 结果
     */
    @Override
    public int deleteOdsOrderById(Long id)
    {
        return odsOrderMapper.deleteOdsOrderById(id);
    }
}
